package com.kaifamiao.io.d0923;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;

public class FieldDemo1 {

    public static void main(String[] args) {
        Class<Student> studentClass = Student.class;

        try {
            Constructor<Student> constructor = studentClass.getDeclaredConstructor(String.class);

            Student student = constructor.newInstance("zhangsan");

            // 内省机制
            PropertyDescriptor name = new PropertyDescriptor("name", studentClass);

            System.out.println(name.getReadMethod());
            System.out.println(name.getWriteMethod());

        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IntrospectionException e) {
            e.printStackTrace();
        }
    }
}
